<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/WEB-INF/pages/common/head.jsp"%>
<script type="text/javascript" src="${ctx }/js/utils/json.js"></script>
<script type="text/javascript">
	//表单数据
	var datagrid;
	//本页面的提示信息
	var message = $.messager;
	var customerCombogrid;
	//弹出Dialog
	var entityDialog;
	$(function() {
		//加载表格的数据
		datagrid = $('#datagrid').datagrid({
			toolbar : '#tb',
			remoteSort: true,          //是否服务器排序
			showFooter : true,
			pagination : false,
			pageList : [ DATAGRIDMAXPAGE ],
			rowStyler : function(index, row) {
				if (row.hasError) {
					return "background:#ffc0cb;";
				}
			}
		});
		 $("#file").change(function(){
			 removeAll();
				var excel = $(this).val();
				var right = true;
				if (!excel) {
					right = false;
				}
				var ps = excel.split(".");
				if (ps.length < 2) {
					right = false;
				} else {
					var format = ps[ps.length - 1].toLowerCase();
					if (format != "xls") {
						right = false;
					} else {
						var url ='${path}/excel/answerProblemExcel/excelUpload.do';
						$("#answerProblemForm").attr("action",url);
						$("#answerProblemForm").submit();
						imonJYRH.showZone();
					}
				}
				if (!right) {
					$.messager.alert("错误", "请选择上传xls格式的文件!", "error");
					return false;
				}	
			});
	});
	 function typeFormatter(value,row,index){
	        <c:forEach var="dict" items="${typeList}">
	            if(row['typeJanuary']=='${dict.code}'){
	               return '<span style="color:red">${dict.name}</span>'
	            }
	        </c:forEach>
	        }
	//  模版下载
	function excelModel() {
		$("#answerProblemForm").attr("action","${path}/excel/answerProblemExcel/excelModel.do").submit();
	}
	function saveAll(docheck) {
		//收集数据
		var effectData = new Object();
		var msg="";
		var rows = datagrid.datagrid('getRows');
		if (rows.length) {
			for ( var i = 0; i < rows.length; i++) {
				if(rows[i].hasError){				
					$.messager.alert('错误', '数据有错误，请修改正确后重新导入！', 'error');
					return;
				}
			}
			imonJYRH.showZone();
			$.ajax({
						url:'${path}/excel/answerProblemExcel/ajaxSave.do',
						data : effectData,
						cache : false,
						type : 'POST',
						async : true,
						dataType : "json",
					    success : function(reMsg) {
					    	imonJYRH.hideZone();
					    	if(reMsg.success){			
					    		parent.message.show({msg :'保存成功',title : '提示',showType:'slide'});
					    		parent.reloadFrame();
								parent.returnResult();
					    	} else {
					    		if (reMsg.obj) {
						    		$.messager.confirm('提示', reMsg.obj, function(r){
						    			if (r) saveAll(false);
					    			});
					    		} else {
					    			parent.message.show({msg : '<font color=red>' + reMsg.msg + '</font>' ,title : '错误',showType:'slide'});
					    		}
					    	} 
		                }
				});			
			
		} else {
			$.messager.alert('提示', '请添加明细');
		}
	}
	function OnUploadCompleted(reMsg){
		imonJYRH.hideZone();
		reMsg = eval('(' + reMsg + ')'); 
		if ((reMsg.obj) && (reMsg.obj.tips)) {
			$.messager.confirm('提示', reMsg.obj.tips, function(r){
				if (r) 
					uploadFile(false);
			});
		}
		if ((reMsg.obj) && (reMsg.obj.details) && (reMsg.obj.details.length > 0)) {
			var obj = {
				'total' : reMsg.obj.details.length,
				'rows' : reMsg.obj.details,
				'footer' : reMsg.obj.footer
			};
			datagrid.datagrid('loadData', obj);
			//calTotal();
		}
		if ((reMsg.obj) && (reMsg.obj.errors) && (reMsg.obj.errors.length > 0)) {
			var str = '<ul>';
			for (var i=0;i<reMsg.obj.errors.length;i++) {
				str += '<li style="color:red;">'+reMsg.obj.errors[i] + "</li>";
			}
			str += '</ul>';
			$("#win").window('open');
			document.getElementById("message").innerHTML=str;
		}
		if(reMsg.success){
			message.show({msg : '上传成功！<br/>' + reMsg.msg ,title : '提示',showType:'slide'});
		} else {		
			if (reMsg.msg) {
				var s = '<font color=red>' + reMsg.msg + '</span>';
				message.show({msg : s ,title : '错误',showType:'slide'});
			}
		}
	}
	function removeAll() {
		$('#datagrid').datagrid('loadData', {
			total : 0,
			rows : []
		});
		$('#datagrid').datagrid('reload');
	}
</script>
</head>
<body class="easyui-layout">
	<form id="answerProblemForm" enctype="multipart/form-data"
		target="target" method="post">
		<div data-options="region:'north'" title="" style="overflow:hidden;">
			<div id="searchbar" class="datagrid-toolbar" style="height: 80;">
				<fieldset>
					<table class="tableForm" id="tableForm" width="100%">
						<legend>
							<spring:message code='msg.import' />
						</legend>
						<tr>
							<td align="right"><span class="red">*</span> <spring:message
									code='label.upload.filePath' /></td>
							<td><input id="file" type="file" onchange="getFileName();"
								name="file" />
							</td>
						</tr>
					</table>
				</fieldset>
			</div>
		</div>
		<div data-options="region:'center'">
			<div id="tb">
				<a class="easyui-linkbutton" href="javascript:void(0);" plain="true"
					iconCls="icon-save" onclick="saveAll();"><spring:message
						code='button.save' /> </a> <a class="easyui-linkbutton"
					iconCls="icon-ok" onclick="excelModel()" plain="true"
					href="javascript:void(0);"><spring:message
						code='button.templetDownload' /> </a>
			</div>
			<table id="datagrid" fit="true" nowrap="true" rownumbers="false"
				pagination="true" singleSelect="true" idField="row">
				<thead>
					<tr>
						<th field="ck" checkbox="true" rowspan="2"></th>
						<th field="supplierCode" width="100" align="center" rowspan="2">SupplierCode<br />供应商代码</th>
						<th field="year" width="80" align="center" rowspan="2">Year<br />年份</th>
						<th width="120" align="center" colspan="2">January<br />一月</th>
						<th width="120" align="center" colspan="2">February<br />二月</th>
						<th width="120" align="center" colspan="2">March<br />三月</th>
						<th width="120" align="center" colspan="2">April<br />四月</th>
						<th width="120" align="center" colspan="2">May<br />五月</th>
						<th width="120" align="center" colspan="2">June<br />六月</th>
						<th width="120" align="center" colspan="2">July<br />七月</th>
						<th width="120" align="center" colspan="2">August<br />八月</th>
						<th width="120" align="center" colspan="2">September<br />九月</th>
						<th width="120" align="center" colspan="2">October<br />十月</th>
						<th width="120" align="center" colspan="2">November<br />十一月</th>
						<th width="120" align="center" colspan="2">December<br />十二月</th>
					</tr>
					<tr>
						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}" field="typeJanuary" width="60" align="center">类型</th>
						<th field="valueJanuary" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeFebruary" width="60" align="center">类型</th>
						<th field="valueFebruary" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeMarch" width="60" align="center">类型</th>
						<th field="valueMarch" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeApril" width="60" align="center">类型</th>
						<th field="valueApril" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeMay" width="60" align="center">类型</th>
						<th field="valueMay" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeJune" width="60" align="center">类型</th>
						<th field="valueJune" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeJuly" width="60" align="center">类型</th>
						<th field="valueJuly" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeAugust" width="60" align="center">类型</th>
						<th field="valueAugust" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeSeptember" width="60" align="center">类型</th>
						<th field="valueSeptember" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}" field="typeOctober" width="60" align="center">类型</th>
						<th field="valueOctober" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeNovember" width="60" align="center">类型</th>
						<th field="valueNovember" width="60" align="center">分数</th>

						<th data-options="formatter:function(value){ if(value=='1'){return 'NOT GOOD'}else if(value=='2'){return 'SATISFACTORY'}else if(value=='3'){return 'GOOD,VERY QUICK'}else{return ''}}"  field="typeDecember" width="60" align="center">类型</th>
						<th field="valueDecember" width="60" align="center">分数</th>
					</tr>
				</thead>
			</table>
		</div>
	</form>
	<div id="entityDialog" class="easyui-dialog" title="My Dialog"
		style="width:1000px;height:500px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true">
		<iframe scrolling="auto" id='openEntityCUIframe' frameborder="0"
			src="" style="width:100%;height:100%;"></iframe>
	</div>
	<div
		style="z-index: -1; position: absolute; left: 0; top: 0;display: none;">
		<iframe id="target" name="target" frameborder="12"> </iframe>
	</div>
	<div id="win" class="easyui-window" style="width:600px;height:500px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true"
		title="导入错误提示">
		<div id="message"></div>
	</div>
</body>
</html>